//
//  PictureChooseView.m
//  DreamSoftReimburse
//
//  Created by ZJ on 17/4/15.
//  Copyright © 2017年 ZJ. All rights reserved.



#import "PictureChooseView.h"
#import "ZJAdditions.h"
@interface PictureChooseView ()

/** 选择按钮 */
@property (nonatomic, strong) UIButton *button;
@end

@implementation PictureChooseView

- (instancetype)initWithFrame:(CGRect)frame bgImageName:(NSString *)bgImageName imageName:(NSString *)imageName
{
    self = [super initWithFrame:frame];
    if (self) {
    
        //背景虚线框的imageView
        UIImageView *bGLImageView = [[UIImageView alloc]initWithFrame:self.bounds];
        bGLImageView.image = [UIImage imageNamed:bgImageName];
        bGLImageView.contentMode = UIViewContentModeScaleAspectFit;
        [self addSubview:bGLImageView];
        [self addSubview:self.imageView];
        [self addSubview:self.button];
        self.button.center = self.imageView.center;

        self.imageView.image = [UIImage imageNamed:imageName];
        
    }
    return self;
}

#pragma mark - 点击事件
- (void)action_selectPhoto{
    if (self.delegate) {
        [self.delegate selectPhotoButtonClick:self];
    }
}

#pragma mark - Setter


#pragma mark - Getters

- (UIImageView *)imageView{
    if (_imageView == nil){
        _imageView = [[UIImageView alloc]initWithFrame:CGRectMake(8 * [UIScreen zj_screenWScale], 8 * [UIScreen zj_screenHScale], self.width - 16 * [UIScreen zj_screenWScale], self.height - 16 * [UIScreen zj_screenHScale])];
        _imageView.contentMode = UIViewContentModeScaleAspectFit;
        
        _imageView.autoresizesSubviews = YES;
        
        _imageView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;

    }
    return _imageView;
}
- (UIButton *)button{
    if (_button == nil){
        _button = [UIButton zj_textButton:nil fontSize:10 normalColor:nil highlightedColor:nil backImageName:@"btn_camera"] ;
        [_button setBackgroundImage:[UIImage imageNamed:@"btn_camera"] forState:UIControlStateHighlighted];
        [_button addTarget:self action:@selector(action_selectPhoto) forControlEvents:UIControlEventTouchUpInside];
    }
    return _button;
}
@end
